import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false
Vue.use(ElementUI)
  // import store from './store/index.js'
const axios = require('axios')
axios.defaults.baseURL = 'https://oneday.dylucas.com/App/index.php/Goods/'
  // axios.defaults.headers.common['Authorization'] = 'AUTH_TOKEN'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
const promiseArr = {} // 用于记录每个请求的取消方法
var cancel,
  Axioss = axios.create({
    responseType: 'json',
    withCredentials: true, // 设置 withCredentials 使请求带上 `cookies`
    cancelToken: new axios.CancelToken(function(c) {
      cancel = c // 记录当前请求的取消方法
    })
  })

// 设置一个拦截器，每次发起请求前取消掉在进行中的相同请求
Axioss.interceptors.request.use(function(config) {
  if (promiseArr[config.url]) {
    promiseArr[config.url] = cancel
  } else {
    promiseArr[config.url] = cancel
  }
  // store.dispatch('showLoading') //  发起loding
  return config
}, function(err) {
  return Promise.reject(err)
})

axios.interceptors.response.use(function(response) {
  // store.dispatch('hideLoading')
  return response
}, function(error) {
  return Promise.reject(error)
})
Vue.prototype.$http = Axioss
window.router = router
  /* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {
    App
  }
})